package com.yc.cloud.admin.controller;

import com.yc.cloud.admin.dto.request.HwDeviceGroupSaveReqDto;
import com.yc.cloud.admin.service.HwDeviceGroupService;
import com.yc.cloud.admin.vo.AlgStrategyVo;
import com.yc.cloud.admin.vo.HwDeviceGroupStrategyVo;
import com.yc.cloud.admin.vo.HwDeviceGroupVo;
import com.yc.cloud.common.basic.api.ResponseResult;
import com.yc.cloud.common.basic.dto.BasePageReqDTO;
import com.yc.cloud.common.orm.CommonPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name = "硬件设备分组管理")
@RequestMapping("/device-group")
@RequiredArgsConstructor
public class HwDeviceGroupController {

    private final HwDeviceGroupService hwDeviceGroupService;

    @Operation(summary = "更新设备组内的设备列表(全量替换)")
    @PutMapping("/{groupId}/devices")
    public ResponseResult<Boolean> updateGroupDevices(@PathVariable("groupId") Long groupId, @RequestBody List<Long> deviceIds) {
        return ResponseResult.success(hwDeviceGroupService.updateGroupDevices(groupId, deviceIds));
    }

    @Operation(summary = "创建设备分组")
    @PostMapping
    public ResponseResult<Boolean> create(@Validated @RequestBody HwDeviceGroupSaveReqDto saveReqDto) {
        return ResponseResult.success(hwDeviceGroupService.create(saveReqDto));
    }

    @Operation(summary = "更新设备分组")
    @PutMapping("/{id}")
    public ResponseResult<Boolean> update(@PathVariable("id") Long id, @Validated @RequestBody HwDeviceGroupSaveReqDto saveReqDto) {
        return ResponseResult.success(hwDeviceGroupService.update(id, saveReqDto));
    }

    @Operation(summary = "删除设备分组")
    @DeleteMapping("/{id}")
    public ResponseResult<Boolean> delete(@PathVariable("id") Long id) {
        return ResponseResult.success(hwDeviceGroupService.delete(id));
    }

    @Operation(summary = "获取设备分组详情")
    @GetMapping("/{id}")
    public ResponseResult<HwDeviceGroupVo> getById(@PathVariable("id") Long id) {
        return ResponseResult.success(hwDeviceGroupService.getVOById(id));
    }

    @Operation(summary = "分页查询设备分组")
    @GetMapping
    public ResponseResult<CommonPage<HwDeviceGroupVo>> list(@Validated BasePageReqDTO pageReqDTO) {
        return ResponseResult.success(hwDeviceGroupService.list(pageReqDTO));
    }
    
    @Operation(summary = "更新设备组绑定的策略列表(全量替换)")
    @PutMapping("/{groupId}/strategies")
    public ResponseResult<Boolean> updateGroupStrategies(@PathVariable("groupId") Long groupId, @RequestBody List<Long> strategyIds) {
        return ResponseResult.success(hwDeviceGroupService.updateGroupStrategies(groupId, strategyIds));
    }
    
    @Operation(summary = "获取设备分组绑定的策略列表")
    @GetMapping("/{groupId}/strategies")
    public ResponseResult<List<HwDeviceGroupStrategyVo>> getGroupStrategies(@PathVariable("groupId") Long groupId) {
        return ResponseResult.success(hwDeviceGroupService.getGroupStrategies(groupId));
    }

    @Operation(summary = "刷新设备分组数据")
    @PostMapping("/refresh")
    public ResponseResult<Boolean> refresh() {
        return ResponseResult.success(hwDeviceGroupService.refreshData());
    }
}
 